package com.zlm.lock;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author zlm
 * @date 2025/4/18
 */
public class Main {

    public static void main(String[] args) throws InterruptedException {
        int[] count = new int[]{1000};

        MyLock lock = new MyLock();
        List<Thread> threads= new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            threads.add(new Thread(() -> {
                lock.lock();
                for (int j = 0; j < 10; j++) {
                    lock.lock();
                    count[0]--;
                }
                for (int j = 0; j < 10; j++) {
                    lock.unlock();
                }
                lock.unlock();
            }));
        }
        threads.forEach(Thread::start);
        for (Thread thread : threads) {
            thread.join();
        }
        System.out.println(count[0]);
    }
}
